package list;

import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.*;

/**
 * @Auther ljn
 * @Date 2019/12/24
 * 测试使用Iterator的时候修改list
 */
public class ChangeListWhenUseIterator {

    @Test
    public void test1(){
        List<String> result = Lists.newArrayList();
        ArrayList<String> list2 = Lists.newArrayList();
        list2.addAll(Arrays.asList("JL,DXM".split(",")));
        String content = "JL,DXM";
        List<String> list1 = Arrays.asList(content.split(","));
        for (String e:list1) {
            Iterator<String> iterator = list2.iterator();
            while (iterator.hasNext()){
                String next = iterator.next();
                if(next.contains(e)){
                    result.add(next);
                    iterator.remove();
                }
            }
        }
        System.out.println(result.size());
    }

    @Test
    public void test2(){
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("a");
        list.add("a");
        list.add("a");
        System.out.println(list.size());
        list.removeIf(e->"a".equals(e));
        System.out.println(list.size());
    }
}
